package com.fanfan.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.fanfan.pojo.User;
import com.fanfan.pojo.domain.ResponseResult;
import com.fanfan.pojo.vo.UserDto;
import com.fanfan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/user")
public class UserController {
    @Autowired
    UserService userService;
    @GetMapping("/list")
    public ResponseResult listUser(Integer pageNum, Integer pageSize, User user){
        return userService.listUser(pageNum, pageSize, user);
    }
    @PostMapping
    public ResponseResult addUser(@RequestBody UserDto userDto){
        return userService.addUser(userDto);
    }
    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable Long id){
        userService.getBaseMapper().deleteById(id);
        return ResponseResult.okResult();
    }
    @GetMapping("/{id}")
    public ResponseResult showUser(@PathVariable Long id){
        return userService.showUser(id);
    }
    @PutMapping
    public ResponseResult updateUser(@RequestBody UserDto userDto){
        return userService.updateUser(userDto);
    }
    @PutMapping("changeStatus")
    public ResponseResult changeStatus(@RequestBody User user){
        userService.updateById(user);
        return ResponseResult.okResult();
    }


}
